import uploadFactory from '../../utils/uploadFactory'
import InteractionUtil from '../../shell/ui/interaction';
Page({

  /**
   * 页面的初始数据
   */
  data: {
    sexs: [{
      label: '男',
      value: 1
    }, {
      label: '女',
      value: 2
    }],
    sexIndex: 0,
    region: ['请', '选', '择'],
    date: '',
    userInfo: {},
    nickName: ''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getUserInfo()
  },
  getUserInfo() {
    wx.$http().request('AppMaster/Account/accountExtraInfo').then(res => {
      const {
        _data
      } = res
      const {
        data
      } = _data
      const {
        sex,
        birthday,
        province,
        city
      } = data
      const {
        sexs
      } = this.data
      const sexIndex = sexs.findIndex(item => item.value * 1 === sex * 1)
      this.setData({
        sexIndex,
        userInfo: data,
        date: birthday
      })
    })
  },
  sexChange(e) {
    const {
      value
    } = e.detail
    this.setData({
      sexIndex: value * 1
    })
  },
  nameInput(e) {
    const {
      value
    } = e.detail
    this.setData({
      nickName: value
    })
  },
  areaChange(e) {},
  birthdayChange(e) {
    const {
      value
    } = e.detail
    this.setData({
      date: value
    })
  },
  modifyPwd() {
    wx.navigateTo({
      url: '/subPage/modifyPwd/index',
    })
  },
  chooseImage(e) {
    wx.chooseImage({
      success: (res) => {
        const {
          tempFilePaths
        } = res
        const {
          userInfo
        } = this.data
        userInfo.user_img = tempFilePaths
        this.setData({
          userInfo
        })
      },
    })
  },
  submitForm() {
    uploadFactory.upLoadFile(item.imgs, 'pay_voucher').then(res => {
      wx.$http().request({
        url: '/AppMaster/Pay/addPayVoucher',
        data: {

        },
        success: res => {
          const {
            data
          } = res
          if (data.result === 0) {
            InteractionUtil.showSuccess('修改成功!')
          }
        }
      })
    })
  },
  submitHandler(e) {
    const {
      userInfo,
      nickName,
      region,
      sexIndex,
      date,
      sexs
    } = this.data
    const {
      user_img
    } = userInfo
    const sex = sexs[sexIndex]['value']
    wx.$http().request({
      url: 'AppMaster/Account/saveAccountExtraInfo',
      data: {
        nickname: nickName,
        sex,
        provice: '',
        city: '',
        birthday: date,
        user_img
      },
      success: res => {
        console.log(res)
      }
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})